<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="../../../common/include.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<jsp:include page="../../../common/head.jsp">
			 <jsp:param name="_useCalendar" value="true"/>
		</jsp:include>

		<title>费用核销</title>
		<script language="JavaScript">
			//表单是否被修改过
			var editState=false;
			function saveData(feeId){
				$("#nextFeeId").val(feeId);
				var objarr = new Array(
					["feeWrittenOff.billAmountAdjust","调整票据金额","float","10.4"],
					["feeWrittenOff.billCountAdjust","调整票据张数","int","3"],
					["feeWrittenOff.certificateAmountAdjust","调整凭证金额","float","10.4"], 
					["feeWrittenOff.certificateCountAdjust","调整凭证张数","int","3"], 
					["feeWrittenOff.adjustRemark","调整备注","max","String:500"],
					["feeWrittenOff.billAmountWrittenOff","核销票据金额","float","10.4"],
					["feeWrittenOff.billCountWrittenOff","核销票据张数","int","3"],
					["feeWrittenOff.certificateAmountWrittenOff","核销凭证金额","float","10.4"], 
					["feeWrittenOff.certificateCountWrittenOff","核销凭证张数","int","3"], 
					["feeWrittenOff.writtenOffRemark","核销备注","max","String:500"],
					["feeWrittenOff.billAmountLeaveReview","本次留审票据金额","float","10.4"], 
					["feeWrittenOff.billCountLeaveReview","本次留审票据张数","int","3"], 
					["feeWrittenOff.certificateAmountLeaveReview","本次留审凭证金额","float","10.4"],
					["feeWrittenOff.certificateCountLeaveReview","本次留审凭证张数","int","3"],
					["feeWrittenOff.leaveReviewRemark","本次留审备注","max","String:500"], 
					["feeWrittenOff.billAmountLeaveReviewEarly","前期留审票据金额","float","10.4"],
					["feeWrittenOff.billCountLeaveReviewEarly","前期留审票据张数","int","3"],
					["feeWrittenOff.certificateAmountLeaveReviewEarly","前期留审凭证金额","float","10.4"], 
					["feeWrittenOff.certificateCountLeaveReviewEarly","前期留审凭证张数","int","3"], 
					["feeWrittenOff.leaveReviewEarlyRemark","前期留审备注","max","String:500"],
					["feeWrittenOff.billAmountRetruned","退票票据金额","float","10.4"],
					["feeWrittenOff.billCountRetruned","退票票据张数","int","3"],
					["feeWrittenOff.certificateAmountRetruned","退票凭证金额","float","10.4"], 
					["feeWrittenOff.certificateCountRetruned","退票凭证张数","int","3"], 
					["feeWrittenOff.leaveReviewRetrunedRemark","退票备注","max","String:500"]
				);
				if(xj.CheckAll(objarr))
				{
					if(confirm("确认保存？"))
					{
						document.getElementById("form1").submit();
					}
				}
			}
			function editData(feeId)
			{
				if(editState==true)
				{
					if(confirm("是否保存当前核销信息"))
					{
						saveData(feeId);
					}
					else
						window.location.href="updateDetailFeeWrittenOff.do?feeTypeId=${feeTypeId}&feeReportId=${feeWrittenOff.feeReportId}&targetId=${targetId}&nextFeeId="+feeId;
				}
				else
					window.location.href="updateDetailFeeWrittenOff.do?feeTypeId=${feeTypeId}&feeReportId=${feeWrittenOff.feeReportId}&targetId=${targetId}&nextFeeId="+feeId;
			}
			//计算数值
			function calFee(prefix)
			{
				editState = true;
				var amount = $("#"+prefix).val();
				var adjust = $("#"+prefix+"Adjust").val();
				
				var leaveReview = $("#"+prefix+"LeaveReview").val();
				var feeRetention_leaveReview = $("#feeRetention_"+prefix+"LeaveReview").text();
				var leaveReviewEarly = $("#"+prefix+"LeaveReviewEarly").val();
				var retruned = $("#"+prefix+"Retruned").val();
				if(isNaN(amount)||amount=="")
					amount = 0;
				if(isNaN(adjust)||adjust=="")
					adjust = 0;
				if(isNaN(leaveReview)||leaveReview=="")
					leaveReview = 0;
				if(isNaN(feeRetention_leaveReview)||feeRetention_leaveReview=="")
					feeRetention_leaveReview = 0;
				if(isNaN(leaveReviewEarly)||leaveReviewEarly=="")
					leaveReviewEarly = 0;
				if(isNaN(retruned)||retruned=="")
					retruned = 0;
				if(parseFloat(leaveReviewEarly)>parseFloat(feeRetention_leaveReview))
				{
					alert("前期留审调整数不能大于存留数");
					$("#"+prefix+"LeaveReviewEarly").val("");
					return;
				}
				//核销金额=申报金额+调整金额-本次留审金额+前期留审金额-退票信息
				var writtenOff = parseFloat(amount)+parseFloat(adjust)-parseFloat(leaveReview)+parseFloat(leaveReviewEarly)-parseFloat(retruned);
				$("#"+prefix+"WrittenOff").val(writtenOff);
			}
			//返回
			function goBack()
			{
				window.top.close();
			}
			$.ready = function()
			{
				var dataIsUpdated = '${param.dataIsUpdated}';
				if(dataIsUpdated!='')
				{
					window.top.returnValue="ok";
				}
			}
		</script>
	</head>
	<body>
	<form action="updateDetailFeeWrittenOff.do" name="form1" id="form1" method="post">
	<input type="hidden" name="nextFeeId" id="nextFeeId" value=""/>
	<input type="hidden" name="feeWrittenOff.feeId" value="${feeWrittenOff.feeId}"/>
	<input type="hidden" name="feeWrittenOff.feeReportId" id="feeReportId" value="${feeWrittenOff.feeReportId}"/>


	<input type="hidden" name="billAmountLeaveReview_o" value="${feeWrittenOff.billAmountLeaveReview}"/>
	<input type="hidden" name="billCountLeaveReview_o" value="${feeWrittenOff.billCountLeaveReview}"/>
	<input type="hidden" name="certificateAmountLeaveReview_o" value="${feeWrittenOff.certificateAmountLeaveReview}"/>
	<input type="hidden" name="certificateCountLeaveReview_o" value="${feeWrittenOff.certificateCountLeaveReview}"/>
	<input type="hidden" name="billAmountLeaveReviewEarly_o" value="${feeWrittenOff.billAmountLeaveReviewEarly}"/>
	<input type="hidden" name="billCountLeaveReviewEarly_o" value="${feeWrittenOff.billCountLeaveReviewEarly}"/>
	<input type="hidden" name="certificateAmountLeaveReviewEarly_o" value="${feeWrittenOff.certificateAmountLeaveReviewEarly}"/>
	<input type="hidden" name="certificateCountLeaveReviewEarly_o" value="${feeWrittenOff.certificateCountLeaveReviewEarly}"/>
	<div id="body_div">
	<w:ShowTitle name="费用核销" useSubmitKey="false">
	<w:TitleButton funcName="保存" onClickFunction="saveData('')" urlImg="${ctx}/images/main/save.png"/>
	<w:TitleButton funcName="返回" onClickFunction="goBack()" urlImg="${ctx}/images/main/back.png"/>
	</w:ShowTitle>
	<div id="body_content">
		<table width="100%">
			<tr>
              <td width="80">地区</td>
              <td class="left_align">
				${feeDetail.areaName}
			  </td>
              <td width="80"><span class="left_align">事业部</span></td>
              <td class="left_align">
				${feeDetail.areaDeptName}
			  </td>
			  <td width="80">发生对象</td>
              <td class="left_align">
              	${feeDetail.feeTarget}
              </td>
              <td width="80">对象名称
              </td>
              <td width="80">
              	${feeDetail.targetName}
              </td>
              <td width="80">费用类别</td>
              <td class="left_align">
              	${feeDetail.feeTypeName}
              </td>
			 </tr>
          </table>
		  <table width="100%">
			<tr>
                      <td width="80" class="td_title">票据金额</td>
                      <td width="80" class="td_title">票据张数</td>
                      <td width="80" class="td_title">凭证金额</td>
                      <td width="80" class="td_title">凭证张数</td>
                      <td class="td_title">费用日期</td>
                      <td class="td_title">登记日期</td>
                      <td width="100" class="td_title">操作</td>
                    </tr>
			<c:forEach items="${feeDetailList}" var="obj">
				<tr>
					<td class="left_align">${obj.billAmount}</td>
					<td class="left_align">${obj.billCount}</td>
					<td class="left_align">${obj.certificateAmount}</td>
					<td class="left_align">${obj.certificateCount}</td>
					<td class="left_align"><fmt:formatDate value='${obj.feeDate}' pattern="yyyy-MM-dd" /></td>
					<td class="left_align"><fmt:formatDate value='${obj.createDate}' pattern="yyyy-MM-dd" /></td>
					<td>
						<a href="#" onclick="javascript:editData('${obj.feeId}')">核销</a>
					</td>
				</tr>
			</c:forEach>
		</table>
          <table width="100%">
               <tr>
                <td width="80" class="td_title">项目</td>
                <td width="100" class="td_title">申报</td>
                <td width="160" class="td_title">调整信息 </td>
                <td width="160" class="td_title">核销信息</td>
                <td width="160" class="td_title">本次留审金额</td>
                <td width="100" class="td_title">前期留审</td>
                <td width="160" class="td_title">前期留审调整</td>
                <td width="160" class="td_title">退票信息</td>
              <td>&nbsp;</td>
              </tr>
              <tr>
                <td class="right_align">票据金额</td>
                <td class="right_align">${feeDetail.billAmount}
                <input type="hidden" name="billAmount" id="billAmount" value="${feeDetail.billAmount}"/>
                </td>
                <td class="right_align"><input type="text" name="feeWrittenOff.billAmountAdjust" id="billAmountAdjust" value="${feeWrittenOff.billAmountAdjust}" onchange="calFee('billAmount')"/></td>
                <td class="right_align"><input type="text" name="feeWrittenOff.billAmountWrittenOff" id="billAmountWrittenOff" value="${feeWrittenOff.billAmountWrittenOff}" readonly="readonly"/></td>
                <td class="right_align"><input type="text" name="feeWrittenOff.billAmountLeaveReview" id="billAmountLeaveReview" value="${feeWrittenOff.billAmountLeaveReview}" onchange="calFee('billAmount')"/></td>
                <td class="right_align" id="feeRetention_billAmountLeaveReview">${feeRetention.billAmountLeaveReview}</td>
                <td class="right_align"><input type="text" name="feeWrittenOff.billAmountLeaveReviewEarly" id="billAmountLeaveReviewEarly" value="${feeWrittenOff.billAmountLeaveReviewEarly}" onchange="calFee('billAmount')"/></td>
                <td class="right_align"><input type="text" name="feeWrittenOff.billAmountRetruned" id="billAmountRetruned" value="${feeWrittenOff.billAmountRetruned}" onchange="calFee('billAmount')"/></td>
              <td class="right_align">&nbsp;</td>
              </tr>
              <tr>
                <td class="right_align">票据张数</td>
                <td class="right_align">${feeDetail.billCount}
                	<input type="hidden" name="billCount" id="billCount" value="${feeDetail.billCount}"/>
                </td>
                <td class="right_align"><input type="text" name="feeWrittenOff.billCountAdjust" id="billCountAdjust" value="${feeWrittenOff.billCountAdjust}" onchange="calFee('billCount')"/></td>
                <td class="right_align"><input type="text" name="feeWrittenOff.billCountWrittenOff" id="billCountWrittenOff" value="${feeWrittenOff.billCountWrittenOff}" readonly="readonly"/></td>
                <td class="right_align"><input type="text" name="feeWrittenOff.billCountLeaveReview" id="billCountLeaveReview" value="${feeWrittenOff.billCountLeaveReview}" onchange="calFee('billCount')"/></td>
                <td class="right_align" id="feeRetention_billCountLeaveReview">${feeRetention.billCountLeaveReview}</td>
                <td class="right_align"><input type="text" name="feeWrittenOff.billCountLeaveReviewEarly" id="billCountLeaveReviewEarly" value="${feeWrittenOff.billCountLeaveReviewEarly}" onchange="calFee('billCount')"/></td>
                <td class="right_align"><input type="text" name="feeWrittenOff.billCountRetruned" id="billCountRetruned" value="${feeWrittenOff.billCountRetruned}" onchange="calFee('billCount')"/></td>
              <td class="right_align">&nbsp;</td>
              </tr>
              <tr>
                <td class="right_align">凭证金额</td>
                <td class="right_align">${feeDetail.certificateAmount}
                <input type="hidden" name="certificateAmount" id="certificateAmount" value="${feeDetail.certificateAmount}"/>
                </td>
                <td class="right_align"><input type="text" name="feeWrittenOff.certificateAmountAdjust" id="certificateAmountAdjust" value="${feeWrittenOff.certificateAmountAdjust}" onchange="calFee('certificateAmount')"/></td>
                <td class="right_align"><input type="text" name="feeWrittenOff.certificateAmountWrittenOff" id="certificateAmountWrittenOff" value="${feeWrittenOff.certificateAmountWrittenOff}" readonly="readonly"/></td>
                <td class="right_align"><input type="text" name="feeWrittenOff.certificateAmountLeaveReview" id="certificateAmountLeaveReview" value="${feeWrittenOff.certificateAmountLeaveReview}" onchange="calFee('certificateAmount')"/></td>
                <td class="right_align" id="feeRetention_certificateAmountLeaveReview">${feeRetention.certificateAmountLeaveReview}</td>
                <td class="right_align"><input type="text" name="feeWrittenOff.certificateAmountLeaveReviewEarly" id="certificateAmountLeaveReviewEarly" value="${feeWrittenOff.certificateAmountLeaveReviewEarly}" onchange="calFee('certificateAmount')"/></td>
                <td class="right_align"><input type="text" name="feeWrittenOff.certificateAmountRetruned" id="certificateAmountRetruned" value="${feeWrittenOff.certificateAmountRetruned}" onchange="calFee('certificateAmount')"/></td>
              <td class="right_align">&nbsp;</td>
              </tr>
			  <tr>
                <td class="right_align">凭证张数</td>
                <td class="right_align">${feeDetail.certificateCount}
                <input type="hidden" name="certificateCount" id="certificateCount" value="${feeDetail.certificateCount}"/>
                </td>
                <td class="right_align"><input type="text" name="feeWrittenOff.certificateCountAdjust" id="certificateCountAdjust" value="${feeWrittenOff.certificateCountAdjust}" onchange="calFee('certificateCount')"/></td>
                <td class="right_align"><input type="text" name="feeWrittenOff.certificateCountWrittenOff" id="certificateCountWrittenOff" value="${feeWrittenOff.certificateCountWrittenOff}" readonly="readonly"/></td>
                <td class="right_align"><input type="text" name="feeWrittenOff.certificateCountLeaveReview" id="certificateCountLeaveReview" value="${feeWrittenOff.certificateCountLeaveReview}" onchange="calFee('certificateCount')"/></td>
                <td class="right_align" id="feeRetention_certificateCountLeaveReview">${feeRetention.certificateCountLeaveReview}</td>
                <td class="right_align"><input type="text" name="feeWrittenOff.certificateCountLeaveReviewEarly" id="certificateCountLeaveReviewEarly" value="${feeWrittenOff.certificateCountLeaveReviewEarly}" onchange="calFee('certificateCount')"/></td>
                <td class="right_align"><input type="text" name="feeWrittenOff.certificateCountRetruned" id="certificateCountRetruned" value="${feeWrittenOff.certificateCountRetruned}" onchange="calFee('certificateCount')"/></td>
              <td class="right_align">&nbsp;</td>
			  </tr>
              <tr>
                <td class="right_align">总金额</td>
                <td class="right_align" id="totalAmount">${feeDetail.billAmount+feeDetail.certificateAmount}</td>
                <td class="right_align" id="totalAmountAdjust">${feeWrittenOff.billAmountAdjust+feeWrittenOff.certificateAmountAdjust}</td>
                <td class="right_align" id="totalAmountWrittenOff">${feeWrittenOff.billAmountWrittenOff+feeWrittenOff.certificateAmountWrittenOff}</td>
                <td class="right_align" id="totalAmountLeaveReview">${feeWrittenOff.billAmountLeaveReview+feeWrittenOff.certificateAmountLeaveReview}</td>
                <td class="right_align" id="feeRetention_totalAmountLeaveReview">${feeRetention.billAmountLeaveReview+feeRetention.certificateAmountLeaveReview}</td>
                <td class="right_align" id="totalAmountLeaveReviewEarly">${feeWrittenOff.billAmountLeaveReviewEarly+feeWrittenOff.certificateAmountLeaveReviewEarly}</td>
                <td class="right_align" id="totalAmountRetruned">${feeWrittenOff.billAmountRetruned+feeWrittenOff.certificateAmountRetruned}</td>
              <td class="right_align">&nbsp;</td>
              </tr>
              <tr>
                <td class="right_align">总张数</td>
                <td class="right_align" id="totalCount">${feeDetail.billCount+feeDetail.certificateCount}</td>
                <td class="right_align" id="totalCountAdjust">${feeWrittenOff.billCountAdjust+feeWrittenOff.certificateCountAdjust}</td>
                <td class="right_align" id="totalCountWrittenOff">${feeWrittenOff.billCountWrittenOff+feeWrittenOff.certificateCountWrittenOff}</td>
                <td class="right_align" id="totalCountLeaveReview">${feeWrittenOff.billCountLeaveReview+feeWrittenOff.certificateAmountLeaveReview}</td>
                <td class="right_align" id="feeRetention_TotalCountLeaveReview">${feeRetention.billCountLeaveReview+feeRetention.certificateCountLeaveReview}</td>
                <td class="right_align" id="totalCountLeaveReviewEarly">${feeWrittenOff.billCountLeaveReviewEarly+feeWrittenOff.certificateCountLeaveReviewEarly}</td>
                <td class="right_align" id="totalCountRetruned">${feeWrittenOff.billCountRetruned+feeWrittenOff.certificateCountRetruned}</td>
              <td class="right_align">&nbsp;</td>
              </tr>
			  <tr>
                <td class="right_align">备注</td>
                <td class="right_align">&nbsp;</td>
                <td class="right_align"><textarea name="feeWrittenOff.adjustRemark">${feeWrittenOff.adjustRemark}</textarea></td>
                <td class="right_align"><textarea name="feeWrittenOff.writtenOffRemark">${feeWrittenOff.writtenOffRemark}</textarea></td>
                <td class="right_align"><textarea name="feeWrittenOff.leaveReviewRemark">${feeWrittenOff.leaveReviewRemark}</textarea></td>
                <td class="right_align">&nbsp;</td>
                <td class="right_align"><textarea name="feeWrittenOff.leaveReviewEarlyRemark">${feeWrittenOff.leaveReviewEarlyRemark}</textarea></td>
                <td class="right_align"><textarea name="feeWrittenOff.leaveReviewRetrunedRemark">${feeWrittenOff.leaveReviewRetrunedRemark}</textarea></td>
              <td class="right_align">&nbsp;</td>
			  </tr>
          </table>
			</div>
		</div>	
		</form>
	</body>
</html>